<?php
// +----------------------------------------------------------------------
// | 07FLYCRM [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------

namespace app\ten\controller;

use think\db;

/**
 * 用户控制器
 */
class TenUser extends TenBase
{

    public function __construct()
    {
        parent::__construct();

        // 租户类型
        $tenant_type_list = $this->logicTenTenantType->getTenTenantTypeList([],'','',false);
        $this->assign('tenant_type_list', $tenant_type_list);
    }

    /**
     * 列表
     */
    public function show()
    {
        return $this->fetch('show');
    }

    // 列表json
    public function show_json()
    {
        $where = [];
        if (!empty($this->param['keywords'])) {
            $where['username|mobile|realname'] = ['like', '%' . $this->param['keywords'] . '%'];
        }
        $list = $this->logicTenUser->getTenUserList($where);
        return $list;
    }

    /**
     * 添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicTenUser->tenUserAdd($this->param));
        return $this->fetch('add');
    }

    /**
     * 用户编辑
     */
    public function edit()
    {
        IS_POST && $this->jump($this->logicTenUser->tenUserEdit($this->param));
        $info = $this->logicTenUser->getTenUserInfo(['id' => $this->param['id']]);

        $this->assign('info', $info);
        return $this->fetch('edit');
    }

    //重置密码
    public function resetPwd()
    {
        IS_POST && $this->jump($this->logicTenUser->userResetPwd($this->param));
        $info = $this->logicTenUser->getTenUserInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('reset_pwd');
    }

    /**
     * 删除
     */
    public function del()
    {
        $where = empty($this->param['id']) ? ['id' => 0] : ['id' => $this->param['id']];
        $this->jump($this->logicTenUser->tenUserDel($where));
    }

    /**
     * 用户详细
     */
    public function detail()
    {
        IS_POST && $this->jump($this->logicTenUser->tenUserEdit($this->param));
        $info = $this->logicTenUser->getTenUserInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('detail');
    }


    /**
     * 创建租户
     */
    public function createTenant()
    {
        IS_POST && $this->jump($this->logicTenUser->userCreateTenant($this->param));
        $info = $this->logicTenUser->getTenUserInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('create_tenant');
    }

    /**
     * 启用
     */
    public function set_visible()
    {
        $this->jump($this->logicTenBase->setField('TenUser', $this->param));
    }

    /**
     * 排序
     */
    public function set_sort()
    {
        $this->jump($this->logicTenBase->setSort('TenUser', $this->param));
    }
}